#include "junix.h"
#include <semaphore.h>

int main(int argc, char **argv)
{
	if(argc==1)
		err_quit("Usage:%s file",argv[0]);

	sem_t *ps;
	if( (ps=sem_open(argv[1],O_CREAT)) == SEM_FAILED)
		err_sys("sem_open");

	while(1)
	{
		if(sem_wait(ps)==-1)
			err_sys("sem_wait");
		printf("*");
		if(sem_post(ps)==-1)
			err_sys("sem_post");
		usleep(1000);
	}

	if(sem_close(ps)==-1)
		err_sys("sem_close");

	return 0;
}

